package gui;

import java.awt.*;
import javax.swing.*;
/**
 * Cette classe gere la barre d'outils du bas. Elle connecte tous les "listeners" des composants graphiques.
 * @author Romain POGU
 * @author Anthony MAUGENDRE
 * @version 1.0
 *
 */
public class BarreOutils extends Panel {
	/**
	 * 
	 */
	private JSpinner champM,champAlpha,champBeta,champK,champR,champIterations;
	private static final long serialVersionUID = -7468747342788455621L;
	public Button toggle;
	public Label labelNbVilles,labelLongueurElastique;
	/**
	 * Constructeur
	 * @param frame Frame � laquelle on ajoute la barre d'outils
	 */
	public BarreOutils(FenetAffiche frame) {
		//parametres de l'enonce
		//r=50
		//m=3
		//k=50
		//alpha=0.7
		//beta=0.1
		//nbIterations=100
		setLayout(new GridLayout(10,2));
		// Label Alpha:
		add(new Label("Alpha:"));
		// Champ Alpha:
		champAlpha=new JSpinner(new SpinnerNumberModel(0.7, 0.1, 2, 0.1));
		add(champAlpha);
		
		// Label Beta:
		add(new Label("Beta:"));
		// Champ Beta:
		champBeta=new JSpinner(new SpinnerNumberModel(0.1, 0.01, 1, 0.01));
		add(champBeta);
		
		// Label M:
		add(new Label("M(mult nb points):"));
		// Champ M:
		champM=new JSpinner(new SpinnerNumberModel(3, 1, 5, 0.5));
		add(champM);
		
		// Label R:
		add(new Label("R(rayon):"));
		// Champ R:
		champR=new JSpinner(new SpinnerNumberModel(50, 10, 100, 2));
		add(champR);
		
		// Label K:
		add(new Label("K:"));
		// Champ K:
		champK=new JSpinner(new SpinnerNumberModel(50, 20, 100, 5));
		add(champK);
		
		// Label Iterations:
		add(new Label("It:"));
		// Champ Iterations:
		champIterations=new JSpinner(new SpinnerNumberModel(100, 100, 1000, 100));
		add(champIterations);
		
		add(new Label());
		add(new Label());
		add(new Label("Nombre de viles:"));
		labelNbVilles=new Label("0");
		add(labelNbVilles);
		add(new Label("Distance:"));
		labelLongueurElastique=new Label("N/A");
		add(labelLongueurElastique);
		
		// Bouton Run
		toggle = new Button("Lancer");
		add(toggle);
		toggle.addActionListener(new ControlItemToggleButton(frame));
		
		// Bouton Effacer
		Button delete = new Button("Effacer");
		add(delete);
		delete.addActionListener(new ControlItemButtonDelete(frame));

	}
	
	public double getM(){
		Number n=(Number)champM.getValue();
		return n.doubleValue();
	}
	
	public double getR(){
		Number n=(Number)champR.getValue();
		return n.doubleValue();
	}
	
	public double getK(){
		Number n=(Number)champK.getValue();
		return n.doubleValue();
	}
	
	public double getAlpha(){
		Number n=(Number)champAlpha.getValue();
		return n.doubleValue();
	}
	
	public double getBeta(){
		Number n=(Number)champBeta.getValue();
		return n.doubleValue();
	}
	
	public double getIterations(){
		Number n=(Number)champIterations.getValue();
		return n.doubleValue();
	}

    public void setM(double M){
		this.champM.setValue((Number)M);
	}

    public void setR(double R){
		this.champR.setValue((Number)R);
	}

    public void setK(double K){
		this.champK.setValue((Number)K);
	}

    public void setAlpha(double Alpha){
		this.champAlpha.setValue((Number)Alpha);
	}
    
    public void setBeta(double Beta){
		this.champBeta.setValue((Number)Beta);
	}

    public void setIterations(double Iterations){
		this.champIterations.setValue((Number)Iterations);
	}

}
